import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


export const constantRoutes = [

  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'dashboard',
        meta: {title: '首页', icon: 'dashboard', affix: true}
      }
    ]
  },


  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: {title: '关于我的', icon: 'user', noCache: true}
      }
    ]
  },
  {
    path: '/person',
    component: Layout,
    redirect: '/person/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/person/Person'),
        name: 'Person',
        meta: {title: '个人中心', icon: 'user', noCache: true}
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/user',
    component: Layout,
    meta: {title: '系统管理', icon: 'user', affix: true},

    children: [
      {
        path: 'user1',
        component: () => import('@/views/tab/User'),
        name: 'dashboard',
        meta: {title: '用户信息', affix: true}, noCache: true, roles: ['editor']},



    ]
  },
  {
    path: '/news',
    component: Layout,
    meta: {title: '系统管理', icon: 'user', affix: true},

    children: [
      {
        path: 'news',
        component: () => import('@/views/news/News'),
        name: 'news',
        meta: {title: '我的动态', icon:'guide',affix: true}},]},
  {
    path: '/book',
    component: Layout,
    meta: {title: '系统管理', icon: 'user', affix: true},

    children: [
      {
        path: 'book',
        component: () => import('@/views/book/Book'),
        name: 'book',
        meta: {title: '图书鉴赏', icon:'book',affix: true}},]},

  {
    path: '/chart',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/analysis/Chart'),
        name: 'Chart',
        meta: {title: '数据分析', icon: 'data', noCache: true}
      }
    ]
  },
  {
    path: '/chat',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/chat/Chat'),
        name: 'Chat',
        meta: {title: '聊天室', icon: 'wechat', noCache: true}
      }
    ]
  },
  {
    path: '/messages',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/chat/Message'),
        name: 'Messages',
        meta: {title: '留言与回复', icon: 'pl', noCache: true}
      }
    ]
  },
  {
    path: '/weather',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/analysis/Weather'),
        name: 'Weather',
        meta: {title: '天气预报', icon: 'weath', noCache: true}
      }
    ]
  },
  {
    path: '/pay',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/pay/Pay'),
        name: 'pay',
        meta: {title: '沙箱支付', icon: 'pay', noCache: true}
      }
    ]
  },
  {
    path: '/role',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/chat/Roles'),
        name: 'role',
        meta: {title: '权限管理', icon: 'role', noCache: true}
      }
    ]
  },
  {
    path: '/icon',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/icons/index'),
        name: 'Icons',
        meta: {title: '图标大全', icon: 'icon', noCache: true}
      }
    ]
  },


  {
    path: '/map',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/map/Map'),
        name: 'map',
        meta: {title: '地图', icon: 'map', noCache: true}
      }
    ]
  },

  {
    path: '/login/login',



        component: () => import('@/views/login/index'),
        name: 'map',
        meta: {title: '退出登录', icon: 'logout', noCache: true}


  },

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
